﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Ch09Ex03
{
   class Program
   {
      static void Main(string[] args)
      {
            Student stu1 = new Student()
            {
                IDCode = "lily",
                Age = 24,
                Grent = new Grent() { Name = "五年三班" }
            };
            //深拷贝，stu1的改变不影响stu2
            Student stu2 = stu1.DeepClone() as Student;
            //浅拷贝，stu1的改变影响stu2
            //Student stu2 = stu1.Clone() as Student;
            if (stu2 == null)
            {
                Console.WriteLine("转换失败");
                Console.ReadKey();
                return;
            }

            Console.WriteLine(stu2.IDCode);
            Console.WriteLine(stu2.Age);
            Console.WriteLine(stu2.Grent.ToString());

            Console.WriteLine();
            Console.WriteLine("重新为stu1赋值");
            Console.WriteLine();

            stu1.IDCode = "Anagle";
            stu1.Age += 10;
            stu1.Grent.Name = "六年二班";
            Console.WriteLine(stu2.IDCode);
            Console.WriteLine(stu2.Age);
            Console.WriteLine(stu2.Grent.ToString());
            Console.ReadKey();
        }
   }
}